package com.freshfresh.view;



import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.freshfresh.activity.R;

public class AlertDialog
{
  private static Dialog dialog;
  private Button btn_neg;
  private Button btn_pos;
  private Context context;
  private Display display;
  private ImageView img_line;
  private ImageView iv_imageview;
  private LinearLayout lLayout_bg;
  private boolean showMsg = false;
  private boolean showNegBtn = false;
  private boolean showPosBtn = false;
  private boolean showTitle = false;
  private TextView txt_msg;
  private TextView txt_msg_small;
  private TextView txt_title;

  public AlertDialog(Context paramContext)
  {
    this.context = paramContext;
    this.display = ((WindowManager)paramContext.getSystemService("window")).getDefaultDisplay();
  }

  private void setLayout()
  {
    if ((!this.showTitle) && (!this.showMsg))
    {
      this.txt_title.setText("提示");
      this.txt_title.setVisibility(0);
    }
    if (this.showTitle)
      this.txt_title.setVisibility(0);
    if (this.showMsg)
      this.txt_msg.setVisibility(0);
    if ((!this.showPosBtn) && (!this.showNegBtn))
    {
      this.btn_pos.setText("确定");
      this.btn_pos.setVisibility(8);
      this.btn_pos.setBackgroundResource(2130837523);
      this.btn_pos.setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          AlertDialog.dialog.dismiss();
        }
      });
    }
    if ((this.showPosBtn) && (this.showNegBtn))
    {
      this.btn_pos.setVisibility(0);
      this.btn_pos.setBackgroundResource(2130837522);
      this.btn_neg.setVisibility(0);
      this.btn_neg.setBackgroundResource(2130837521);
      this.img_line.setVisibility(0);
    }
    if ((this.showPosBtn) && (!this.showNegBtn))
    {
      this.btn_pos.setVisibility(0);
      this.btn_pos.setBackgroundResource(2130837523);
    }
    if ((!this.showPosBtn) && (this.showNegBtn))
    {
      this.btn_neg.setVisibility(0);
      this.btn_neg.setBackgroundResource(2130837523);
    }
  }

  public AlertDialog builder()
  {
    View localView = LayoutInflater.from(this.context).inflate(R.layout.view_alertdialog, null);
    this.lLayout_bg = ((LinearLayout)localView.findViewById(R.id.lLayout_bg));
    this.txt_title = ((TextView)localView.findViewById(R.id.txt_title));
    this.txt_title.setVisibility(8);
    this.txt_msg = ((TextView)localView.findViewById(R.id.txt_msg));
    this.txt_msg.setVisibility(8);
    this.txt_msg_small = ((TextView)localView.findViewById(R.id.txt_msg_small));
    this.txt_msg_small.setVisibility(8);
    this.iv_imageview = ((ImageView)localView.findViewById(R.id.iv_imageview));
    this.iv_imageview.setVisibility(8);
    this.btn_neg = ((Button)localView.findViewById(R.id.btn_neg));
    this.btn_neg.setVisibility(8);
    this.btn_pos = ((Button)localView.findViewById(R.id.btn_pos));
    this.btn_pos.setVisibility(8);
    this.img_line = ((ImageView)localView.findViewById(R.id.img_line));
    this.img_line.setVisibility(8);
    if (dialog != null)
      dialog.dismiss();
    dialog = new Dialog(this.context, R.style.AlertDialogStyle);
    dialog.setContentView(localView);
    dialog.getWindow().setWindowAnimations(R.style.AlertDialogAnimation);
    this.lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams((int)(0.85D * this.display.getWidth()), -2));
    return this;
  }

  public TextView getTxt_msg()
  {
    return this.txt_msg;
  }

  public AlertDialog setCancelable(boolean paramBoolean)
  {
    dialog.setCancelable(paramBoolean);
    return this;
  }

  public AlertDialog setImageView(Integer paramInteger)
  {
    if (paramInteger != null)
    {
      this.iv_imageview.setVisibility(0);
      this.iv_imageview.setImageResource(paramInteger.intValue());
      return this;
    }
    this.iv_imageview.setVisibility(8);
    return this;
  }

  public AlertDialog setMsg(String paramString)
  {
    this.showMsg = true;
    if ("".equals(paramString))
    {
      this.txt_msg.setText("内容");
      return this;
    }
    this.txt_msg.setText(paramString);
    return this;
  }

  public AlertDialog setMsg(String paramString, Integer paramInteger)
  {
    this.showMsg = true;
    if ("".equals(paramString))
      this.txt_msg.setText("内容");
    while (true)
    {
      if (paramInteger != null)
        txt_msg.setGravity(paramInteger.intValue());
      return this;
    }
  }

  public AlertDialog setMsg(String paramString, Integer paramInteger1, Integer paramInteger2)
  {
    this.showMsg = true;
    if ("".equals(paramString))
      this.txt_msg.setText("内容");
    while (true)
    {
      if (paramInteger1 != null)
        this.txt_msg.setGravity(paramInteger1.intValue());
      if (paramInteger2 != null)
        this.txt_msg.setTextColor(this.context.getResources().getColor(paramInteger2.intValue()));
      return this;
    }
  }

  public AlertDialog setMsg_small(String paramString, Integer paramInteger1, Integer paramInteger2)
  {
    this.txt_msg_small.setVisibility(0);
    if ("".equals(paramString))
      this.txt_msg_small.setText("内容");
    while (true)
    {
      if (paramInteger1 != null)
        this.txt_msg_small.setGravity(paramInteger1.intValue());
      if (paramInteger2 != null)
        this.txt_msg_small.setTextColor(this.context.getResources().getColor(paramInteger2.intValue()));
      return this;
    }
  }

  @SuppressLint("ResourceAsColor")
public AlertDialog setNegativeButton(String paramString, final View.OnClickListener paramOnClickListener)
  {
    this.showNegBtn = true;
    if ("".equals(paramString))
      this.btn_neg.setText("取消");
    this.btn_neg.setBackgroundColor(R.color.gray);
    while (true)
    {
      this.btn_neg.setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          if (paramOnClickListener != null)
            paramOnClickListener.onClick(paramAnonymousView);
          AlertDialog.dialog.dismiss();
        }
      });
      return this;
    }
  }

  public AlertDialog setPositiveButton(String paramString, final View.OnClickListener paramOnClickListener)
  {
    this.showPosBtn = true;
    if ("".equals(paramString)){
      this.btn_pos.setText("确定");
    }else{
	 this.btn_pos.setText("拨打");
    }
    while (true)
    {
      this.btn_pos.setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          if (paramOnClickListener != null)
            paramOnClickListener.onClick(paramAnonymousView);
          AlertDialog.dialog.dismiss();
        }
      });
      return this;
    }
  }

  public AlertDialog setTitle(String paramString)
  {
    this.showTitle = true;
    if ("".equals(paramString))
    {
      this.txt_title.setText("标题");
      return this;
    }
    this.txt_title.setText(paramString);
    return this;
  }

  public AlertDialog show()
  {
    setLayout();
    if (this.context != null)
      dialog.show();
    return this;
  }
}